<!-- XHTML 1.0 Strict -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<meta name="author" content="Rachid Touzani" />
<meta name="keywords" content=" css, dropdowns, dropdown menu, drop-down, menu, navigation, nav, horizontal, vertical left-to-right, vertical right-to-left, horizontal linear, horizontal upwards, cross browser, internet explorer, ie, firefox, safari, opera, browser, lwis" />
<meta name="description" content="Clean, standards-friendly, modular framework for dropdown menus" />
<link href="../css/dropdown.vertical.css" media="screen" rel="stylesheet" type="text/css" />
<link href="../css/default.ultimate.css" media="screen" rel="stylesheet" type="text/css" />

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Demonstration of class ODESolver usage</title>
<link rel="stylesheet" type="text/css" href="../doxygen.css" />
<link rel="stylesheet" type="text/css" href="../tabs.css"  />
</head>

<body bgcolor="#FFFFFF" link="#FF0000" vlink="#FF00FF" alink="#FF00FF">
<p align="center"><a href="../index.html"><img src="../im/ofeli.gif" width="150" border="0"></a></p>

<center>
  <div id="cse" style="width: 60%;">Loading</div>
  <script src="http://www.google.com/jsapi" type="text/javascript"></script>
  <script type="text/javascript"> 
     google.load('search', '1', {language : 'en', style : google.loader.themes.SHINY});
     google.setOnLoadCallback(function() {
        var customSearchOptions = {};  var customSearchControl = new google.search.CustomSearchControl(
        '012396140824982761142:-qrywxcfi_o', customSearchOptions);
        customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
        customSearchControl.draw('cse');
     }, true);
   </script>
   <style type="text/css">
     .gsc-control-cse {
     font-family: Verdana, sans-serif;
     border-color: #DAE0E5;
     background-color: #DAE0E5;
   }
   .gsc-control-cse .gsc-table-result { font-family: Verdana, sans-serif; }
   input.gsc-input { border-color: #B6BEC5; }
   input.gsc-search-button {
     border-color: #B6BEC5;
     background-color: #D0D1D4;
   }
   .gsc-tabHeader.gsc-tabhInactive {
     border-color: #999999;
     background-color: #EEEEEE;
   }
   .gsc-tabHeader.gsc-tabhActive {
     border-color: #999999;
     background-color: #999999;
   }
   .gsc-tabsArea { border-color: #999999; }
   .gsc-webResult.gsc-result,
   .gsc-results .gsc-imageResult {
     border-color: #FFFFFF;
     background-color: #FFFFFF;
   }
   .gsc-webResult.gsc-result:hover,
   .gsc-imageResult:hover {
     border-color: #D2D6DC;
     background-color: #EDEDED;
   }
   .gsc-webResult.gsc-result.gsc-promotion:hover {
     border-color: #D2D6DC;
     background-color: #EDEDED;
   }
   .gs-webResult.gs-result a.gs-title:link,
   .gs-webResult.gs-result a.gs-title:link b,
   .gs-imageResult a.gs-title:link,
   .gs-imageResult a.gs-title:link b { color: #0568CD; }
   .gs-webResult.gs-result a.gs-title:visited,
   .gs-webResult.gs-result a.gs-title:visited b,
   .gs-imageResult a.gs-title:visited,
   .gs-imageResult a.gs-title:visited b { color: #0568CD; }
   .gs-webResult.gs-result a.gs-title:hover,
   .gs-webResult.gs-result a.gs-title:hover b,
   .gs-imageResult a.gs-title:hover,
   .gs-imageResult a.gs-title:hover b { color: #0568CD; }
   .gs-webResult.gs-result a.gs-title:active,
   .gs-webResult.gs-result a.gs-title:active b,
   .gs-imageResult a.gs-title:active,
   .gs-imageResult a.gs-title:active b { color: #0568CD; }
   .gsc-cursor-page { color: #0568CD; }
   a.gsc-trailing-more-results:link { color: #0568CD; }
   .gs-webResult .gs-snippet,
   .gs-imageResult .gs-snippet,
   .gs-fileFormatType { color: #5F6A73; }
   .gs-webResult div.gs-visibleUrl,
   .gs-imageResult div.gs-visibleUrl { color: #5F6A73; }
   .gs-webResult div.gs-visibleUrl-short { color: #5F6A73; }
   .gs-webResult div.gs-visibleUrl-short { display: none; }
   .gs-webResult div.gs-visibleUrl-long { display: block; }
   .gs-promotion div.gs-visibleUrl-short { display: none; }
   .gs-promotion div.gs-visibleUrl-long { display: block; }
   .gsc-cursor-box { border-color: #FFFFFF; }
   .gsc-results .gsc-cursor-box .gsc-cursor-page {
      border-color: #999999;
      background-color: #FFFFFF;
      color: #0568CD;
   }
   .gsc-results .gsc-cursor-box .gsc-cursor-current-page {
      border-color: #999999;
      background-color: #999999;
      color: #0568CD;
   }
   .gsc-webResult.gsc-result.gsc-promotion {
      border-color: #D2D6DC;
      background-color: #D0D1D4;
   }
   .gsc-completion-title { color: #0568CD; }
   .gsc-completion-snippet { color: #5F6A73; }
   .gs-promotion a.gs-title:link,
   .gs-promotion a.gs-title:link *,
   .gs-promotion .gs-snippet a:link { color: #0066CC; }
   .gs-promotion a.gs-title:visited,
   .gs-promotion a.gs-title:visited *,
   .gs-promotion .gs-snippet a:visited { color: #0066CC; }
   .gs-promotion a.gs-title:hover,
   .gs-promotion a.gs-title:hover *,
   .gs-promotion .gs-snippet a:hover { color: #0066CC; }
   .gs-promotion a.gs-title:active,
   .gs-promotion a.gs-title:active *,
   .gs-promotion .gs-snippet a:active { color: #0066CC; }
   .gs-promotion .gs-snippet,
   .gs-promotion .gs-title .gs-promotion-title-right,
   .gs-promotion .gs-title .gs-promotion-title-right *  { color: #333333; }
   .gs-promotion .gs-visibleUrl,
   .gs-promotion .gs-visibleUrl-short { color: #5F6A73; }
   </style>
</center>
</p>
&nbsp;

<div id="mainmenu">
<div class="text">

 <div class="tabs">
   <ul class="tablist">
   <li><a href="../index.html"><span>Home</span></a>
   <li><a href="../overview.html"><span>Overview</span></a>
   <li><a href="../html/index.html"><span>Class Documentation</span></a>
   <li><a href="../fformats.html"><span>File Formats</span></a>
   <li><a href="../tutorial.html"><span>Tutorial</span></a>
   <li class="current"><a href="../demos.html"><span>Demo Codes</span></a>
 </div>

 </div>
 </div>

&nbsp;
<p>
<h2>Demonstration of class LinearSolver usage: Using an iterative solver
 for a PDE</h2>

<p><table border="2" cellpadding="2" cellspacing="0" >
<tr>
<td align="center" width="35"><a href="ls_demo1.html"><img src="../im/backward.gif" border="0"></a></td>
<td align="center" width="35"><a href="../demos.html"><img src="../im/top.gif" border="0"></a></td>
<td align="center" width="35"><a href="ode_demo1.html"><img src="../im/forward.gif" border="0"></a></td>
</tr>
</table></p>

<p>
<SPAN class=TEXT>
In this example, we solve the Poisson equation (Laplace equation with
a right-hand side) by the P<sub>1</sub>-finite element method and by
using the Conjugate Gradient iterative method to solve the linear system.
</SPAN>

<ul type=square>
<li><SPAN class=TEXT>As usual, we start by including the <span class=LOGO>OFELI</span>
principal header file and the header file dealing with the Laplace equation
and defining the namespace <span class=LOGO>OFELI</span>.
We start the program by reading the argument as the mesh file's name. Note that
in the mesh construction phase, the second argument indicates that the
nodes with prescribed boundary conditions (here boundary nodes) are
eliminates from the list of equations. This is recommended when
iterative methods are used.

<p><table bgcolor="#e0f8f7" border="1" frame=box rules=none width=700>
<tr><td>
<pre><font color="blue" size=3>#include "OFELI.h"
#include "Laplace.h"
using namespace OFELI;

int main(int argc, char *argv[])
{
   Mesh ms(argv[1],true);
</font></pre>
</td></tr></table>
</SPAN></p>

<li><SPAN class=TEXT>
We instantiate the matrix as a sparse matrix (instance of
<a href="../html/classOFELI_1_1SpMatrix.html">SpMatrix</a>) and
the vectors <span class=VAR>b</span>, <span class=VAR>x</span>,
<span class=VAR>bc</span> and <span class=VAR>f</span>. Here the
vectors <span class=VAR>b</span> and <span class=VAR>x</span>
stand for the right-hand side and the solution of the system. They
must be dimensioned as the total number of equations (prescribed
degrees of freedom are removed). The vectors <span class=VAR>bc</span>
and <span class=VAR>f</span> stand respectively for the vector
containing imposed values at nodes and the one containing the source
(right-hand side of the PDE). Theses vectors are constructed using the
<a href="../html/classOFELI_1_1Mesh.html">Mesh</a> instance. To
initialize <span class=VAR>f</span> we use a regular expression.
The vector <span class=VAR>bc</span> is set to zero since we impose
homogeneous Dirichlet boundary conditions.
<p><table bgcolor="#e0f8f7" border="1" frame=box rules=none width=700>
<tr><td>
<pre><font color="blue" size=3>   SpMatrix&lt;double&gt; A(ms);
   Vect&lt;double&gt; b(ms.getNbEq()), x(ms.getNbEq()), bc(ms), f(ms);
   f = "exp(-20*(x*x+y*y))";
   bc = 0;
</font></pre>
</td></tr></table>
</SPAN></p>

<li><SPAN class=TEXT>
To construct the finite element equations, we construct a loop over elements,
instantiate for each element an instance of class
<a href="../html/classOFELI_1_1Laplace2DT3.html">Laplace2DT3</a></span>
that deals with the 2-D Laplace equation using P<sub>1</sub>--elements.
The member functions <span class=VAR>LHS</span> and <span class=VAR>BodyRHS</span>
compute the left and right-hand sides of the element equation. The function
<span class=VAR>updateBC</span> adds the contribution of the boundary
condition to the right-hand side. Note that this is actually not
necessary here since we enforce the value 0. We next assemble left and right-hand
sides into the global matrix and right-hand side vector.
<p><table bgcolor="#e0f8f7" border="1" frame=box rules=none width=700>
<tr><td>
<pre><font color="blue" size=3>   MeshElements(ms) {
      Laplace2DT3 eq(theElement);
      eq.LHS();
      eq.BodyRHS(f);
      eq.updateBC(bc);
      eq.ElementAssembly(A);
      eq.ElementAssembly(b);
   }
</font></pre>
</td></tr></table>
</SPAN></p>

<li><SPAN class=TEXT>To solve the linear system, we use an instance of
class <a href="../html/classOFELI_1_1LinearSolver.html">LinearSolver</a></span>
where some parameters are provided. Here we assign at maximum 1000
iterations, a tolerance of 1.e-8 as convergence criterium and no verbosity.
We next solve the linear system by using the Conjugate Gradient method
with the Diagonal preconditioner. This member function returns the
number of performed iterations.
<p><table bgcolor="#e0f8f7" border="1" frame=box rules=none width=700>
<tr><td>
<pre><font color="blue" size=3>   LinearSolver&lt;double&gt; ls(1000,1.e-8,0);
   int nb_it = ls.solve(A,b,x,CG_SOLVER,DIAG_PREC);
   cout &lt;&lt; "Number of iterations: " &lt;&lt; nb_it &lt;&lt; endl;
</font></pre>
</td></tr></table>
</SPAN></p>

<li><SPAN class=TEXT>To end we construct the solution vector by
inserting the prescribed values. This is useful for any
post-processing purposes.
<p><table bgcolor="#e0f8f7" border="1" frame=box rules=none width=700>
<tr><td>
<pre><font color="blue" size=3>   Vect&lt;double&gt; u(ms);
   u.insertBC(ms,x,bc);
   return 0;
}
</font></pre>
</td></tr></table>
</SPAN></p>

</ul></p>


<p><table align="center" border="2" cellpadding="2" cellspacing="0" >
<tr>
<td align="center" width="35"><a href="ls_demo1.html"><img src="../im/backward.gif" border="0"></a></td>
<td align="center" width="35"><a href="../demos.html"><img src="../im/top.gif" border="0"></a></td>
<td align="center" width="35"><a href="ode_demo1.html"><img src="../im/forward.gif" border="0"></a></td>
</tr>
</table>

&nbsp;
<div id="foot_bar">
        Copyright &copy; 1998-2018 Rachid Touzani&nbsp;
</div>

</body>
</html>
